package com.nofeng.wx.webconfig;

import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class WxMpConfig {

    private static final String APP_ID = "wx5948c0e547a72639";
    private static final String APP_SECRET = "1283b792e3ceabfd50f324dd04aa4007";

//    @Value("${wechat.mp.appId}")
    private String appId;

//    @Value("${wechat.mp.appSecret}")
    private String appSecret;

    @Bean
    public WxMpService wxMpService() {
        WxMpService wxMpService = new WxMpServiceImpl();
        wxMpService.setWxMpConfigStorage(wxMpConfigStorage());
        return wxMpService;
    }

    @Bean
    public WxMpConfigStorage wxMpConfigStorage() {
        WxMpDefaultConfigImpl configStorage = new WxMpDefaultConfigImpl();
        configStorage.setAppId(APP_ID);
        configStorage.setSecret(APP_SECRET);
        // 如有需要，可继续设置Token、AES Key等
        // configStorage.setToken(token);
        // configStorage.setAesKey(aesKey);
        return configStorage;
    }
}